/**
 * 账户路由
 * 定义账户相关的API路由
 */
const express = require('express');
const accountController = require('../controllers/accountController');
const authMiddleware = require('../middlewares/auth');

const router = express.Router();

/**
 * @swagger
 * /login: 
 *   post:
 *     summary: 用户登录
 *     tags: [账户]
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               phone:
 *                 type: string
 *                 description: 手机号
 *                 example: '13800138000'
 *               password:
 *                 type: string
 *                 description: 密码，长度为6-20个字符，必须包含字母和数字
 *                 minLength: 6
 *                 maxLength: 20
 *                 pattern: '^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{6,20}$'
 *                 example: 'Abc12345'
 *     responses:
 *       200:
 *         description: 登录成功
 *         content:
 *           application/json:
 *             schema:
 *               $ref: '#/components/schemas/ApiResponse'
 *       400:
 *         description: 参数错误，如手机号或密码格式不正确
 *         content:
 *           application/json:
 *             schema:
 *               $ref: '#/components/schemas/ApiResponse'
 *       401:
 *         description: 未授权，账号或密码错误
 *         content:
 *           application/json:
 *             schema:
 *               $ref: '#/components/schemas/ApiResponse'
 */
// 用户登录
router.post('/login', accountController.login);

/**
 * @swagger
 * /info: 
 *   get:
 *     summary: 获取账户信息
 *     tags: [账户]
 *     security:
 *       - bearerAuth: []
 *     responses:
 *       200:
 *         description: 获取成功
 *         content:
 *           application/json:
 *             schema:
 *               $ref: '#/components/schemas/ApiResponse'
 *       401:
 *         description: 未授权，需要先登录
 *         content:
 *           application/json:
 *             schema:
 *               $ref: '#/components/schemas/ApiResponse'
 *       404:
 *         description: 账户不存在
 *         content:
 *           application/json:
 *             schema:
 *               $ref: '#/components/schemas/ApiResponse'
 */
// 获取账户信息
router.get('/info', authMiddleware, accountController.getAccountInfo);

/**
 * @swagger
 * /update: 
 *   put:
 *     summary: 更新账户信息
 *     tags: [账户]
 *     security:
 *       - bearerAuth: []
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               username:
 *                 type: string
 *                 description: 用户名，长度为3-20个字符
 *                 minLength: 3
 *                 maxLength: 20
 *                 example: '张三'
 *               phone:
 *                 type: string
 *                 description: 手机号
 *                 example: '13800138000'
 *     responses:
 *       200:
 *         description: 更新成功
 *         content:
 *           application/json:
 *             schema:
 *               $ref: '#/components/schemas/ApiResponse'
 *       400:
 *         description: 参数错误，如用户名格式不正确
 *         content:
 *           application/json:
 *             schema:
 *               $ref: '#/components/schemas/ApiResponse'
 *       401:
 *         description: 未授权，需要先登录
 *         content:
 *           application/json:
 *             schema:
 *               $ref: '#/components/schemas/ApiResponse'
 *       404:
 *         description: 账户不存在
 *         content:
 *           application/json:
 *             schema:
 *               $ref: '#/components/schemas/ApiResponse'
 */
// 更新账户信息
router.put('/account/update', authMiddleware, accountController.updateAccount);

module.exports = router;